package com.hkccommunity.service.impl;

import com.hkccommunity.entity.AnswerChild;
import com.hkccommunity.mapper.AnswerChildMapper;
import com.hkccommunity.service.AnswerChildService;
import com.hkccommunity.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.List;

public class AnswerChildServiceImpl implements AnswerChildService {

    private SqlSessionFactory factory = SqlSessionFactoryUtil.getSqlSessionFactory();
    @Override
    public List<AnswerChild> getAnswerChildByParentId(Long parentId) {
        SqlSession sqlSession = factory.openSession();
        AnswerChildMapper mapper = sqlSession.getMapper(AnswerChildMapper.class);
        List<AnswerChild> childList = mapper.getAnswerByParentId(parentId);
        sqlSession.close();
        return childList;
    }

    @Override
    public int addAnswerChild(AnswerChild child) {
        SqlSession sqlSession = factory.openSession();

        AnswerChildMapper mapper = sqlSession.getMapper(AnswerChildMapper.class);
        int i = mapper.addAnswerChild(child);
        sqlSession.commit();
        sqlSession.close();
        return i;

    }
}
